<!-- --------- 实名认证----------- -->
<template>
	<view class="smrz">
		<view class="inputContent">
			<view class="list">
				<view class="leftText">USDT钱包地址：</view>
				<input
					type="text"
					v-model="usdt_src"
					placeholder="请填写你的USDT钱包地址"
					placeholder-class="pl"
				/>
			</view>
			<view class="list">
				<view class="leftText">USDT链名称：</view>
				<input
					:disabled="true"
					v-model="usdt_td"
					placeholder="请填写你的USDT链名称"
					placeholder-class="pl"
				/>
			</view>
			<view class="list">
				<view class="leftText">收款二维码：</view>
				<image
					:style="{ width: `180rpx`, height: `180rpx` }"
					:src="
						usdt_qr_src.data ||
						usdt_qr_src.value ||
						`/static/image/icon-uploadQrCode.png`
					"
					mode="aspectFit"
					@click="chooseImage"
				/>
			</view>
		</view>
		<button @click="submit" class="submit">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				usdt_src: "",
				usdt_td: "TRC20",
				usdt_qr_src: {
					data: "",
					value: "",
				},
			};
		},
		onLoad() {
			this.$request.get("/Home/info/me").then(({ data }) => {
				this.usdt_src = data.usdt_src;
				this.usdt_qr_src.value = data.usdt_qr_src;
			});
		},
		methods: {
			inputNumber({ detail }) {
				!/^[0-9]*$/.test(detail.value) &&
					uni.showToast({ title: "请输入6位数字密码", icon: "none" });
			},
			chooseImage() {
				uni.chooseImage({
					count: 1,
					success: ({ tempFilePaths }) => {
						this.usdt_qr_src.data = tempFilePaths[0];
					},
				});
			},
			async submit() {
				const submitData = async (usdt_qr_src) => {
					const { msg: title } = await this.$request.post("/Home/info/skxg", {
						usdt_src: this.usdt_src,
						usdt_td: this.usdt_td,
						usdt_qr_src,
					});

					uni.showToast({
						title,
						success: () => setTimeout(uni.navigateBack, 1500),
					});
				};

				if (this.usdt_qr_src.data) {
					uni.showToast({ title: "uploading...", icon: "loading" });
					const [fail, result] = await uni.uploadFile({
						url: `${this.$request.defaults.baseURL}/Home/Login/upload`,
						name: "qrcode",
						filePath: this.usdt_qr_src.data,
					});
					if (fail) {
						uni.showToast({ title: "upload fail.", icon: "none" });
						return;
					}

					if (result.data[0] !== "{") {
						result.data = result.data.slice(1);
					}

					const { code, data, msg: title } = JSON.parse(result.data);

					if (!+code) {
						uni.showToast({ title, icon: "none" });
						return;
					}
					submitData(data.qrcode);

					return;
				}

				submitData(this.usdt_qr_src.value);
			},
		},
	};
</script>

<style lang="scss">
	.smrz {
		padding: 30rpx;
		box-sizing: border-box;

		.tips {
			font-size: 24rpx;
			font-family: Alibaba PuHuiTi;
			font-weight: 400;
			color: #999999;
			line-height: 36rpx;
			margin-bottom: 30rpx;
		}

		.inputContent {
			border-radius: 10rpx;
			background: #ffffff;
			padding: 0 20rpx;
			margin-bottom: 150rpx;
			.list {
				display: flex;
				flex-direction: row;
				align-items: center;
				border-bottom: 1rpx solid #e5e5e5;
				padding: 30rpx;

				.leftText {
					width: 250rpx;
					font-size: 30rpx;
					font-family: Alibaba PuHuiTi;
					font-weight: 400;
					color: #1a1a1a;
					margin-right: 10rpx;
				}

				input {
					flex-grow: 1;
				}

				.pl {
					font-size: 24rpx;
					font-family: Alibaba PuHuiTi;
					font-weight: 400;
					color: #999999;
				}
			}
		}

		.submit {
			width: 100%;
			height: 80rpx;
			background: #2a62ff;
			border-radius: 10rpx;
			font-size: 34rpx;
			font-family: Alibaba PuHuiTi;
			font-weight: 400;
			color: #ffffff;
			line-height: 80rpx;
			text-align: center;
		}
	}
</style>
